package com.jsbb.controller.sys;

import com.jsbb.core.Message;
import com.jsbb.dto.sys.SysMenuAddDto;
import com.jsbb.dto.sys.SysMenuQueryDto;
import com.jsbb.dto.sys.SysMenuUpdateDto;
import com.jsbb.service.sys.SysMenuService;
import com.jsbb.vo.sys.SysMenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单管理Controller
 *
 * @author jsbb
 */
@RestController
@RequestMapping("/sys/menu")
@Tag(name = "1.3 系统管理-菜单管理")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @PostMapping("/list")
    @Operation(summary = "获取菜单树")
    public Message<List<SysMenuVo>> list(@Validated @RequestBody SysMenuQueryDto queryDto) {
        List<SysMenuVo> list = sysMenuService.tree(queryDto);
        return Message.success(list);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "获取详情")
    @Parameter(name = "id", description = "ID")
    public Message<SysMenuVo> get(@PathVariable("id") Long id) {
        SysMenuVo menuVo = sysMenuService.get(id);
        return Message.success(menuVo);
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    public Message add(@Validated @RequestBody SysMenuAddDto addDto) {
        sysMenuService.add(addDto);
        return Message.success();
    }

    @PostMapping("/update")
    @Operation(summary = "修改")
    public Message update(@Validated @RequestBody SysMenuUpdateDto updateDto) {
        sysMenuService.update(updateDto);
        return Message.success();
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "删除")
    @Parameter(name = "id", description = "ID")
    public Message delete(@PathVariable("id") Long id) {
        sysMenuService.delete(id);
        return Message.success();
    }
}
